package com.atguigu.gmall.service;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
//@DefaultProperties(defaultFallback = "getTestc")  //出现异常默认熔断
public class MyService {

    @RequestMapping("getTesta")
    public String getTesta(){
        System.out.println("service2002");
        return "getTesta";
    };

    @RequestMapping("getTestb")
    @HystrixCommand(fallbackMethod = "getTestc",commandProperties = {
            @HystrixProperty(name="circuitBreaker.enabled",value = "true"),//是否开启断路器
            @HystrixProperty(name="circuitBreaker.requestVolumeThreshold",value = "10"),//请求次数
            @HystrixProperty(name="circuitBreaker.sleepWindowInMilliseconds",value = "10000"),//时间范围
            @HystrixProperty(name="circuitBreaker.errorThresholdPercentage",value = "60")//失败率达到多少跳匝
    })
    public String getTestb(){
        String s = UUID.randomUUID().toString();
        return s;
    };

    @RequestMapping("getTestc")
    public String getTestc(){
        return "你被熔断了";
    }

}
